let userDao = require('../dao/userDao');
let tokenUtil = require('../token');
let timeUtil = require('../util/timeUtil');
let cmService = require('./cmService');
let apollo = require('../config/apollo');
const {BusiError, SysError} = require('../exception/exception');

class AppService {
    constructor() {
    }

    /**
     * 获取安卓下载链接
     * @param {String} uidEncodeStr
     * @param {String} from
     * @returns {Promise<String>}
     */
    async getDownloadLink(uidEncodeStr, from){
        let baseUrl = apollo.config['download.url'];

        // todo: 获取app当前版本号
        let appVersion = "v1.0.0";

        if (from === "iOS"){
            return baseUrl + "/iOS" + "/jk_app_" + appVersion + ".ipa";
        }

        let ud = "default";

        let uid = tokenUtil.aesDecodeDef(uidEncodeStr);
        let user = await userDao.getUserByUid(uid);
        if(user){
            ud = uid;
        }

        // todo: 判断安装包是否存在, 不存在则远程调用打包服务打包
        return baseUrl + "/android" + "/" + ud + "/jk_app_" + appVersion + ".apk";
    }
}


let appService = new AppService();
module.exports = appService;